class Solution {
public:
    vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
        if(people.size()==0){
            return people;
        }
        sort(people.begin(),people.end(),cmp);
        vector<vector<int>> ans;
        for(int i=0;i<people.size();i++){
            ans.insert(ans.begin()+people[i][1],people[i]);
        }
        return ans;
        /*
        int first=people[0][0];
        int second=people[0][1];
        int pos=0;
        for(int i=0;i<people.size();i++){
            if(people[i][0]<first){
                //swap(people[i],people[pos]);
                people.insert(people.begin()+people[i][1],people[i]);
                people.erase(people.begin()+i+1);
            }
        }
        return people;
        */
    }
    static bool cmp(const vector<int>& a,const vector<int>& b){
        if(a[0]!=b[0]){
            return a[0]>b[0];
        } else{
            return a[1]<b[1];
        }
    }
};